﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Tzync
{
    /*************************************************************************************/
    /* Class to store a Difference between 2 Directories/Files with its type and details */
    /*************************************************************************************/

    public class Difference
    {
        private FileInfo sysFile;
        private DirectoryInfo sysFolder;
        private TreeNode partnerFile, partnerFolder;
        private Pair<DirectionType, OperationType> type;
        private Type itemType;

        //Description     : Constructor to initialise a File-File Difference
        //Pre-Conditions  : sys is not NULL, partner is not NULL, type is not NULL
        //Post-Conditions : Difference values initialised.

        public Difference(FileInfo sys, TreeNode partner, Pair<DirectionType, OperationType> type)
        {
            sysFile = sys;
            partnerFile = partner;
            this.type = type;
            itemType = Type.File;
        }

        //Description     : Constructor to initialise a Directory-Directory Difference
        //Pre-Conditions  : sys is not NULL, partner is not NULL, type is not NULL
        //Post-Conditions : Difference values initialised.

        public Difference(DirectoryInfo sys, TreeNode partner, Pair<DirectionType, OperationType> type)
        {
            sysFolder = sys;
            partnerFolder = partner;
            this.type = type;
            itemType = Type.Folder;
        }

        /*********************************************************/
        /* Accessory Functions for the data members of the class */
        /*********************************************************/

        public FileInfo GetSysFile()
        {
            return sysFile;
        }
        public void SetSysFile(FileInfo sys)
        {
            sysFile = sys;
        }

        public DirectoryInfo GetSysFolder()
        {
            return sysFolder;
        }

        public TreeNode GetPartnerFile()
        {
            return partnerFile;
        }

        public TreeNode GetPartnerFolder()
        {
            return partnerFolder;
        }

        public Type GetItemType()
        {
            return itemType;
        }

        public void SetSysFile(TreeNode pf)
        {
            partnerFile = pf;
        }

        public Pair<DirectionType, OperationType> GetPairType()
        {
            return type;
        }
        public void SetPairType(Pair<DirectionType, OperationType> t)
        {
            type = t;
        }

        /**************************************************************/
        /* Accessory Functions for the data members of the class end !*/
        /**************************************************************/

        //Function to convert the Difference information into String 

        public String toString()
        {
            String str = "";
            str = itemType.ToString() + " ";
            if (type.First == DirectionType.HDToSystem) str += "HD->Sys ";
            if (type.First == DirectionType.SystemToHD) str += "Sys->HD "; 
            if (type.Second == OperationType.Creation) str += "Creation ";
            if (type.Second == OperationType.Deletion) str += "Deletion ";
            if (type.Second == OperationType.Modification) str += "Modification ";
            if (type.Second == OperationType.CreationCreationConflict) str += "CreationCreationConflict ";
            if (type.Second == OperationType.DeletionDeletionConflict) str += "DeletionDeletionConflict ";
            if (type.Second == OperationType.ModDeleteConflict) str += "ModDeleteConflict ";
            if (type.Second == OperationType.None) str += "None";
            if (itemType == Type.File)
            {
                if(partnerFile.getFullPathA().CompareTo("")!=0) str += partnerFile.getFullPathA();
                else str += partnerFile.getFullPathB();
            }
            else if (itemType == Type.Folder)
            {
                if (partnerFolder.getFullPathA().CompareTo("") != 0) str += partnerFolder.getFullPathA();
                else str += partnerFolder.getFullPathB();
            }            
            return str;
        }

    }

    /*************************/
    /* Class Difference Ends */
    /*************************/
}
